package com.service;

import com.dao.StudentDao;
import com.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 学生管理 Service
 */
@Service
public class StudentService {

    @Autowired
    private StudentDao studentDao;

    /**
     * 保存学生信息
     */
    @Transactional
    public Student save(Student student) {
        int affected = studentDao.save(student);
        return affected > 0 ? student : null;
    }

    /**
     * 根据 ID 查询学生
     */
    @Transactional(readOnly = true)
    public Student findById(Long id) {
        return studentDao.findById(id);
    }

    /**
     * 查询所有学生
     */
    @Transactional(readOnly = true)
    public List<Student> findAll() {
        return studentDao.findAll();
    }
} 